﻿package com.vinyl.controls
{	
	import flash.display.MovieClip;
	import flash.display.GradientType;
	import flash.display.SpreadMethod;
	import flash.geom.*;
	import com.vinyl.controls.ButtonView;
	
	public class SimpleRadioButtonView extends ButtonView
	{
		private var chk;
		
		public function SimpleRadioButtonView( )
		{
			//super( mc );
			
			chk = new MovieClip();
			
			chk.x = 3;
			chk.y = 5;
			
			addChild( chk );
		}
		
		override public function setState( state: String ): void
		{
			graphics.clear();
			chk.graphics.clear();
			
			switch( state )
			{
				case ButtonView.ACTIVE_DOWN:
				case ButtonView.NORMAL_UP:
					
					commonFill( 0xCFCFCF );
					break;
					
				case ButtonView.NORMAL_OVER:
					
					commonFill( 0x3ACAC2 );
					break;
					
				case ButtonView.NORMAL_DOWN:
				case ButtonView.ACTIVE_UP:
					commonFill( 0xCFCFCF );
					commonCheckFill();
					break;
					
				case ButtonView.ACTIVE_OVER:
					commonFill( 0x3ACAC2 );
					commonCheckFill();
					break;
			}
		}
		
		private function commonFill( color )
		{
			var fillType:String = GradientType.LINEAR;
			var colors:Array = [0xccccccc, 0xFFFFFF];
			var alphas:Array = [1, 1];
			var ratios:Array = [0x00, 0xFF];
			var matr:Matrix = new Matrix();
			matr.createGradientBox(16, 16, 45, 0, 0);
			var spreadMethod:String = SpreadMethod.PAD;
			
			var r = 8;
			var tx = 8;
			var ty = 8;
			var c = r * (Math.SQRT2-1);
			var m =r * Math.SQRT2*.5;
	
			with( graphics )
			{
				beginGradientFill( fillType, [color, color], alphas, ratios, matr, spreadMethod ); 
				moveTo(tx+r, ty);
				curveTo(tx+r, ty+c, tx+m, ty+m);
				curveTo(tx+c, ty+r, tx, ty+r);
				curveTo(tx-c, ty+r, tx-m, ty+m);
				curveTo(tx-r, ty+c, tx-r, ty);
				curveTo(tx-r, ty-c, tx-m, ty-m);
				curveTo(tx-c, ty-r, tx, ty-r);
				curveTo(tx+c, ty-r, tx+m, ty-m);
				curveTo(tx+r, ty-c, tx+r, ty);
				endFill();	
			}
	
				
			r = 7;
			tx = 8;
			ty = 8;
			c = r * (Math.SQRT2-1);
			m =r * Math.SQRT2*.5;
			
			with( graphics )
			{
				beginGradientFill( fillType, colors, alphas, ratios, matr, spreadMethod ); 
				
				moveTo(tx+r, ty);
				curveTo(tx+r, ty+c, tx+m, ty+m);
				curveTo(tx+c, ty+r, tx, ty+r);
				curveTo(tx-c, ty+r, tx-m, ty+m);
				curveTo(tx-r, ty+c, tx-r, ty);
				curveTo(tx-r, ty-c, tx-m, ty-m);
				curveTo(tx-c, ty-r, tx, ty-r);
				curveTo(tx+c, ty-r, tx+m, ty-m);
				curveTo(tx+r, ty-c, tx+r, ty);
				endFill();	
			}
		}

		
		private function commonCheckFill()
		{
			var fillType:String = GradientType.LINEAR;
			var colors:Array = [0xccccccc, 0xFFFFFF];
			var alphas:Array = [1, 1];
			var ratios:Array = [0x00, 0xFF];
			var matr:Matrix = new Matrix();
			matr.createGradientBox(16, 16, 45, 0, 0);
			var spreadMethod:String = SpreadMethod.PAD;
			
			var r = 4;
			var tx = 8;
			var ty = 8;
			var c = r * (Math.SQRT2-1);
			var m =r * Math.SQRT2*.5;
	
			with( graphics )
			{
				beginGradientFill( fillType, [0x999999, 0x999999], alphas, ratios, matr, spreadMethod ); 
				moveTo(tx+r, ty);
				curveTo(tx+r, ty+c, tx+m, ty+m);
				curveTo(tx+c, ty+r, tx, ty+r);
				curveTo(tx-c, ty+r, tx-m, ty+m);
				curveTo(tx-r, ty+c, tx-r, ty);
				curveTo(tx-r, ty-c, tx-m, ty-m);
				curveTo(tx-c, ty-r, tx, ty-r);
				curveTo(tx+c, ty-r, tx+m, ty-m);
				curveTo(tx+r, ty-c, tx+r, ty);
				endFill();	
			}
		}
		
	}
}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
